package com.project.andeper.paperproject;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import lecho.lib.hellocharts.model.Axis;
import lecho.lib.hellocharts.model.AxisValue;
import lecho.lib.hellocharts.model.Line;
import lecho.lib.hellocharts.model.LineChartData;
import lecho.lib.hellocharts.model.PointValue;
import lecho.lib.hellocharts.view.LineChartView;

public class ShowElectricActivity extends AppCompatActivity {


    DBManager dbManager = new DBManager(this);
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.chart)
    LineChartView chart;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_electric);
        ButterKnife.bind(this);
        String field = getIntent().getStringExtra("method");
        String value = getIntent().getStringExtra("value");
        title.setText(value+"的用电量");
        List<Integer> integers = dbManager.getElectric(field, value);
        List<PointValue> pointValues = new ArrayList<>();
        pointValues.add(new PointValue(0,integers.get(0)));
        pointValues.add(new PointValue(1,integers.get(1)));
        pointValues.add(new PointValue(2,integers.get(2)));
        pointValues.add(new PointValue(3,integers.get(3)));
        pointValues.add(new PointValue(4,integers.get(4)));
        pointValues.add(new PointValue(5,integers.get(5)));
        pointValues.add(new PointValue(6,integers.get(6)));
        pointValues.add(new PointValue(7,integers.get(7)));
        pointValues.add(new PointValue(8,integers.get(8)));
        String[] x = {"一月","二月","三月","四月","五月","六月","七月","八月","九月"};
        Line line = new Line(pointValues).setColor(Color.BLUE).setCubic(true);
        line.setHasLabelsOnlyForSelected(true);
        List<Line> lines = new ArrayList<Line>();

        lines.add(line);

        LineChartData data = new LineChartData();

        data.setLines(lines);

        Axis axisX = new Axis(); //X轴
        axisX.setName("月份");
        List<AxisValue> mAxisXValues = new ArrayList<AxisValue>();
        for (int i = 0; i < x.length; i++) {
            mAxisXValues.add(new AxisValue(i).setLabel(x[i]));
        }
        axisX.setValues(mAxisXValues);
        axisX.setTextColor(Color.BLACK);
        data.setAxisXBottom(axisX);


        Axis axisY = new Axis();  //Y轴
        axisY.setName("用电量");//y轴标注
        data.setAxisYLeft(axisY);  //Y轴设置在左边
        axisY.setTextColor(Color.BLACK);
        chart.setLineChartData(data);
    }
}
